namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_member 的摘要说明
/// </summary>
public class t_member:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Member __member;
	public String id  
	{
		get{return __member.id;}
		set{ __member.id=value;}
	}
	public String memberID  
	{
		get{return __member.memberID;}
		set{ __member.memberID=value;}
	}
	public String password  
	{
		get{return __member.password;}
		set{ __member.password=value;}
	}
	public String memberName  
	{
		get{return __member.memberName;}
		set{ __member.memberName=value;}
	}
	public String phone  
	{
		get{return __member.phone;}
		set{ __member.phone=value;}
	}
	public String mobile  
	{
		get{return __member.mobile;}
		set{ __member.mobile=value;}
	}
	public String address  
	{
		get{return __member.address;}
		set{ __member.address=value;}
	}
	public DateTime addTime  
	{
		get{return __member.addTime;}
		set{ __member.addTime=value;}
	}
	private static  MemberDao dao=(MemberDao)SpringContext.Context.GetObject("MemberDao");
	public static MemberDao DAO
	{
		get{return dao;}
		
	}
	
	public t_member()
	{
		__member=new Member();
	  	id="";
	  	memberID="";
	  	password="";
	  	memberName="";
	  	phone="";
	  	mobile="";
	  	address="";
	  	addTime=DateTime.Now;
	  // dao=(MemberDao)SpringContext.Context.GetObject("MemberDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("memberID", @"会员代码");
		colNames.Add("memberID");
		m_colLabels.Add("password", @"密码");
		colNames.Add("password");
		m_colLabels.Add("memberName", @"会员名");
		colNames.Add("memberName");
		m_colLabels.Add("phone", @"联系电话");
		colNames.Add("phone");
		m_colLabels.Add("mobile", @"移动电话");
		colNames.Add("mobile");
		m_colLabels.Add("address", @"地址");
		colNames.Add("address");
		m_colLabels.Add("addTime", @"注册时间");
		colNames.Add("addTime");
	  }
	
	}
	public t_member(Member entity )
	{
		__member=entity;
		
	  // dao=(MemberDao)SpringContext.Context.GetObject("MemberDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("memberID", @"会员代码");
		colNames.Add("memberID");
		m_colLabels.Add("password", @"密码");
		colNames.Add("password");
		m_colLabels.Add("memberName", @"会员名");
		colNames.Add("memberName");
		m_colLabels.Add("phone", @"联系电话");
		colNames.Add("phone");
		m_colLabels.Add("mobile", @"移动电话");
		colNames.Add("mobile");
		m_colLabels.Add("address", @"地址");
		colNames.Add("address");
		m_colLabels.Add("addTime", @"注册时间");
		colNames.Add("addTime");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Member));}
     }
	public const string ENTITYNAME="t_member";
	public const int SEQN0=190;
	
    public void checkAdd()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=memberID.Trim().Length;
	if(len>32)
		 throw (new Exception("会员代码字符长度最长不能超过32,当前长度为"+len.ToString()));	
	

	
	len=password.Trim().Length;
	if(len>32)
		 throw (new Exception("密码字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("密码不能为空!"));	
	

	
	len=memberName.Trim().Length;
	if(len>32)
		 throw (new Exception("会员名字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("会员名不能为空!"));	
	

	
	len=phone.Trim().Length;
	if(len>32)
		 throw (new Exception("联系电话字符长度最长不能超过32,当前长度为"+len.ToString()));	
	

	
	len=mobile.Trim().Length;
	if(len>32)
		 throw (new Exception("移动电话字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("移动电话不能为空!"));	
	

	
	len=address.Trim().Length;
	if(len>64)
		 throw (new Exception("地址字符长度最长不能超过64,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("地址不能为空!"));	
	

	//try{Convert.ToDateTime(addTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	addTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入注册时间"));

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=memberID.Trim().Length;
	if(len>32)
		 throw (new Exception("会员代码字符长度最长不能超过32,当前长度为"+len.ToString()));	
	

	
	len=password.Trim().Length;
	if(len>32)
		 throw (new Exception("密码字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("密码不能为空!"));	
	

	
	len=memberName.Trim().Length;
	if(len>32)
		 throw (new Exception("会员名字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("会员名不能为空!"));	
	

	
	len=phone.Trim().Length;
	if(len>32)
		 throw (new Exception("联系电话字符长度最长不能超过32,当前长度为"+len.ToString()));	
	

	
	len=mobile.Trim().Length;
	if(len>32)
		 throw (new Exception("移动电话字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("移动电话不能为空!"));	
	

	
	len=address.Trim().Length;
	if(len>64)
		 throw (new Exception("地址字符长度最长不能超过64,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("地址不能为空!"));	
	

	//try{Convert.ToDateTime(addTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	addTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入注册时间"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("id", id);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__member);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByid()
    {
    
        try
        {
          dao.Delete(__member);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__member);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,memberID);	
m_updateRow(rowNo,ii++,memberName);	
m_updateRow(rowNo,ii++,phone);	
m_updateRow(rowNo,ii++,mobile);	
m_updateRow(rowNo,ii++,address);	
m_updateRow(rowNo,ii++,			addTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)addTime).Hour + ((DateTime)addTime).Minute==0?string.Format("{0:d}",addTime):string.Format("{0:G}",addTime));	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,100,"会员代码");
			m_insertHead(ii++,100,"会员名");
			m_insertHead(ii++,100,"联系电话");
			m_insertHead(ii++,100,"移动电话");
			m_insertHead(ii++,100,"地址");
			m_insertHead(ii++,100,"注册时间");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,memberID);
     	m_insertRow(0,ii++,memberName);
     	m_insertRow(0,ii++,phone);
     	m_insertRow(0,ii++,mobile);
     	m_insertRow(0,ii++,address);
     	m_insertRow(0,ii++,			addTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)addTime).Hour + ((DateTime)addTime).Minute==0?string.Format("{0:d}",addTime):string.Format("{0:G}",addTime));
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,100,"会员代码");
			m_insertHead(ii++,100,"会员名");
			m_insertHead(ii++,100,"联系电话");
			m_insertHead(ii++,100,"移动电话");
			m_insertHead(ii++,100,"地址");
			m_insertHead(ii++,100,"注册时间");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Member obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,obj.memberID.ToString());
m_insertRow(j,ii++,obj.memberName.ToString());
m_insertRow(j,ii++,obj.phone.ToString());
m_insertRow(j,ii++,obj.mobile.ToString());
m_insertRow(j,ii++,obj.address.ToString());
m_insertRow(j,ii++,			obj.addTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)obj.addTime).Hour + ((DateTime)obj.addTime).Minute==0?string.Format("{0:d}",obj.addTime):string.Format("{0:G}",obj.addTime)
);
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Member obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__member=obj;
            	return true;
            }
        
    }
    public static t_member Get(DetachedCriteria dc)
    {
    	
    	Member obj=((MemberDao)SpringContext.Context.GetObject("MemberDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_member( obj );
        
    }
	 public static t_member GetById(String val)
	 {
	 	Member obj=((MemberDao)SpringContext.Context.GetObject("MemberDao"))
	 	.GetById(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_member( obj );
	 	
	 	
	 }
	 public  bool InitById(String val)
	 {
	 	

	 	Member obj=dao.GetById(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__member=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			Controls["id"].Text=id;
		}
		if(Controls["memberID"]!=null)
		{
			Controls["memberID"].Text=memberID;
		}
		if(Controls["password"]!=null)
		{
			Controls["password"].Text=password;
		}
		if(Controls["memberName"]!=null)
		{
			Controls["memberName"].Text=memberName;
		}
		if(Controls["phone"]!=null)
		{
			Controls["phone"].Text=phone;
		}
		if(Controls["mobile"]!=null)
		{
			Controls["mobile"].Text=mobile;
		}
		if(Controls["address"]!=null)
		{
			Controls["address"].Text=address;
		}
		if(Controls["addTime"]!=null)
		{
			Controls["addTime"].Text=			addTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)addTime).Hour + ((DateTime)addTime).Minute==0?string.Format("{0:d}",addTime):string.Format("{0:G}",addTime);
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_member Init(Member item)
    {
        __member=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			
			if(Controls["id"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["id"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{id=v;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
			else
			{
				try{id=Controls["id"].Text;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["memberID"]!=null)
		{
			
			if(Controls["memberID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["memberID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{memberID=v;}
				catch
				{
					 Controls["memberID"].Focus();
					throw  (new Exception("会员代码格式不正确！！"));
				}
				
			}
			else
			{
				try{memberID=Controls["memberID"].Text;}
				catch
				{
					 Controls["memberID"].Focus();
					throw  (new Exception("会员代码格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["password"]!=null)
		{
			
			if(Controls["password"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["password"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{password=v;}
				catch
				{
					 Controls["password"].Focus();
					throw  (new Exception("密码格式不正确！！"));
				}
				
			}
			else
			{
				try{password=Controls["password"].Text;}
				catch
				{
					 Controls["password"].Focus();
					throw  (new Exception("密码格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["memberName"]!=null)
		{
			
			if(Controls["memberName"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["memberName"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{memberName=v;}
				catch
				{
					 Controls["memberName"].Focus();
					throw  (new Exception("会员名格式不正确！！"));
				}
				
			}
			else
			{
				try{memberName=Controls["memberName"].Text;}
				catch
				{
					 Controls["memberName"].Focus();
					throw  (new Exception("会员名格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["phone"]!=null)
		{
			
			if(Controls["phone"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["phone"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{phone=v;}
				catch
				{
					 Controls["phone"].Focus();
					throw  (new Exception("联系电话格式不正确！！"));
				}
				
			}
			else
			{
				try{phone=Controls["phone"].Text;}
				catch
				{
					 Controls["phone"].Focus();
					throw  (new Exception("联系电话格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["mobile"]!=null)
		{
			
			if(Controls["mobile"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["mobile"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{mobile=v;}
				catch
				{
					 Controls["mobile"].Focus();
					throw  (new Exception("移动电话格式不正确！！"));
				}
				
			}
			else
			{
				try{mobile=Controls["mobile"].Text;}
				catch
				{
					 Controls["mobile"].Focus();
					throw  (new Exception("移动电话格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["address"]!=null)
		{
			
			if(Controls["address"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["address"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{address=v;}
				catch
				{
					 Controls["address"].Focus();
					throw  (new Exception("地址格式不正确！！"));
				}
				
			}
			else
			{
				try{address=Controls["address"].Text;}
				catch
				{
					 Controls["address"].Focus();
					throw  (new Exception("地址格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["addTime"]!=null)
		{
			
			if(Controls["addTime"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["addTime"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{addTime=(v==""?new DateTime(1000,1,1):Convert.ToDateTime(v));}
				catch
				{
					 Controls["addTime"].Focus();
					throw  (new Exception("注册时间格式不正确！！"));
				}
				
			}
			else
			{
				try{addTime=(Controls["addTime"].Text==""?new DateTime(1000,1,1):Convert.ToDateTime(Controls["addTime"].Text));}
				catch
				{
					 Controls["addTime"].Focus();
					throw  (new Exception("注册时间格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
